// @include "../code/Namespace.js"
// @include "../code/Function.js"
// @include "../code/Tmpl.js"
/**
 * @fileOverview Object.watch 兼容实现工具
 * 
 * @version watch 1.0
 * @static
 * @author wxq wxqqh@qq.com
 */
/**
 * 命名空间
 * 
 * @namespace
 * @type Object
 */
window.qinglan = window.qinglan || {};

/**
 * Watch 属性监听命名空间<br/>
 * 
 * @namespace
 * @type Object
 */
qinglan.Watch={};
/**
 * 是否已经属性绑定，此属性方法会直接扩展Object原型
 * @private
 * @static
 * @type Boolean
 */
qinglan.Watch.__isBindWatch = false;
/**
 * 进行watch绑定
 * 
 * @public
 * @static
 * @type Function
 */
qinglan.Watch.bindWatch=function(){
	if ( !qinglan.Watch.__isBindWatch && !Object.prototype.watch) {//firefox 原生就支持这个方法
		Object.prototype.watch=function(prop,handler){
			var oldValue = this[prop];
			var newValue = oldValue;
			
			var __getter__ = function(){
				return newValue;
			};
			
			var __setter__ = function(val){
				oldValue = newValue;
				return newValue = handler.call(this,prop,oldValue,newValue);
			};
			
			if (delete this[prop]){
				if(Object.defineProperty){// ECMAScript5
					Object.defineProperty(this,prop,{get : __getter__ , set : __setter__ });
				}else if (Object.prototype.__defineGetter__ && Object.prototype.__defineSetter__){//Fix
					Object.prototype.__defineGetter__.call(this,prop,__getter__);
					Object.prototype.__defineSetter__.call(this,prop,__setter__);
				}
	 		}
		};
	}
	
	if ( !__isBindWatch && !Object.prototype.unwatch){
		Object.prototype.unwatch = function(prop){
			var value = this[prop];
			delete this[prop];
			this[prop] = value;
		};
	}
	qinglan.Watch.__isBindWatch=true;
	return true;
};
